from flask import Flask, render_template, request
from lib.similarityCalculator import findSimilaritySortList
from lib.utils import getFilenameByNumber

app = Flask(__name__, static_folder='101_ObjectCategories/', static_url_path='/public')

@app.route('/')
def Hello():
  return render_template('index.html')

@app.route('/search')
def Search():
  category = request.args.get('category')
  index = request.args.get('index')
  status, message, colorRes, shapeRes, textureRes = findSimilaritySortList(category, int(index))
  if status == 1:
    return render_template('search.html', color = colorRes, shape = shapeRes, texture = textureRes, target_url = (category + '/' + getFilenameByNumber(int(index))))
  else:
    return render_template('error.html', message = message)